use lavender::cache::redis::{*};
use serde::{Serialize,Deserialize};

#[tokio::test]
async fn test_connect(){
    let mut cache  = RedisCache::instance().unwrap();
    let resp:String = cache.get("foo").await.unwrap();
    println!("resp: {:?}",resp);
}

// #[test]
// fn test_connect_by_pass(){
//     let mut conf = RedisConnectInfo::default();
//     conf.pass = Some("12345678".to_owned());

//     let mut cache  = RedisCache::instance_with(conf).unwrap();
//     let resp = cache.get("foo");
//     println!("resp: {:?}",resp);
// }

#[tokio::test]
async fn test_exec(){
    let mut cache  = RedisCache::instance().unwrap();
    let resp:redis::Value = cache.exec("hgetall","hash_demo").await.unwrap();
    println!("resp: {:?}",resp);
}

#[derive(Debug,Clone,Serialize,Deserialize)]
pub struct TestData{
    pub age:i32,
    pub name: String,
}

#[tokio::test]
async fn test_json(){
    let mut cache  = RedisCache::instance().unwrap();
    let key = "json_test";
    let data = TestData{
        age:18,
        name: "zhu".to_owned()
    };
    let _ = cache.set_json(key,&data,Some(30)).await.unwrap();
    println!("set ok!");
    let data_str:TestData = cache.get_json(key).await.unwrap();
    println!("get data is {:?}",data_str);   

}

#[tokio::test]
async fn test_number(){
    let mut cache  = RedisCache::instance().unwrap();
    let key = "number_test";
    let data = 96;
    let _ = cache.set(key,&format!("{}",data),Some(30)).await.unwrap();
    println!("set ok!");
    let data_str:i32 = cache.get(key).await.unwrap();
    println!("get data is {}",data_str);
}

// #[test]
// fn test_format(){
//     const fmt:&str = "http://datacenter-web.eastmoney.com/api/data/v1/get?callback={callbackName}&reportName=RPT_IPO_ABSTOCK&columns=SECURITY_CODE%2CCHANGE_DATE%2CCHANGE_AFTER_FN%2CCHANGE_AFTER_AB%2CTRADE_MARKET_TYPE%2CRANK%2CSECUCODE&quoteColumns=&filter=(SECUCODE%3D%22{code}.{type}%22)&pageNumber=1&pageSize=100&sortTypes=1&sortColumns=CHANGE_DATE&source=QuoteWeb&client=WEB&_={timestamp}";
//     let code = "600396";
//     let type_ = 2;
//     let timestamp = 123456789;
//     println!("{}",format!(fmt,code = code,type = type_,timestamp = timestamp));

// }

